	var allerrornum = 0;
	var totalnum = 0;  
	var postData = ''; 
	// 考试时间
	var time=30;
	function stop(){ 
		return false; 
	} 
	document.oncontextmenu=stop; 
	function createXmlHttp() { 
		var xmlHttp = null; 
		try { 
		//Firefox, Opera 8.0+, Safari 
			xmlHttp = new XMLHttpRequest(); 
		} catch (e) { 
			//IE 
			try { 
			  xmlHttp = new ActiveXObject('Msxml2.XMLHTTP'); 
			} catch (e) { 
			  xmlHttp = new ActiveXObject('Microsoft.XMLHTTP'); 
			} 
		} 
		return xmlHttp; 
	} 

	function submitForm() { 
		var xmlHttp = createXmlHttp(); 
		if(!xmlHttp) { 
			alert('您的浏览器不支持AJAX！'); 
			return 0; 
		} 
		var url = 'score.cgi'; 
		xmlHttp.open('POST', url, true); 
		xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); 
		xmlHttp.onreadystatechange = function() { 
		if(xmlHttp.readyState == 4 && xmlHttp.status == 200) { 
		  if(xmlHttp.responseText == '1') { 
			alert('post successed'); 
		  } 
		} 
	} 
	xmlHttp.send(postData); 
	} 
	function init(){ 
		var spanid; 
		forms = document.getElementById('form1');  totalnum+=forms.length/4; 
		forms = document.getElementById('form2');  totalnum+=forms.length/4; 
		forms = document.getElementById('form3');  totalnum+=forms.length/2; 
		spanid = document.getElementById('totalnum');
		spanid.innerHTML = totalnum; 
		window.sessionStorage.setItem('leave-times', 0)
		spanid = document.getElementById('studentname'); 
		spanid.innerHTML = decodeURI('%E8%AE%A1%E7%AE%97%E6%9C%BA%E5%9F%BA%E7%A1%80'); 
	} 
	function commit() {  
		var i;  
		var rid;  
		var radios; 
		var checkrightflag;
		var forms = document.getElementById('form1');  
		var errornum = forms.length/4;
		allerrornum = 0;
		for (i=0; i<forms.length/4; i++) {  
			radios = document.getElementsByName(forms.elements[i*4].name);  
			rid = document.getElementById('text' + radios[0].name); 
			rid.style.color = 'red';  
			for(var x=0; x<radios.length; x++){  
				if(radios[x].checked == true  && radios[x].value == 'true' ){  
					rid.style.color = 'black';  
					errornum--;
				}
			}  
	}  
	allerrornum = errornum;

	forms = document.getElementById('form2');  
	errornum = forms.length/4;
	for (i=0; i<forms.length/4; i++) {  
		radios = document.getElementsByName(forms.elements[i * 4].name);  
		rid = document.getElementById('text' + radios[0].name);  
		rid.style.color = 'red';  
		checkrightflag = 0;
		for(var x=0; x<radios.length; x++){  
			if( (radios[x].value == 'true' && radios[x].checked == false) || (radios[x].value == 'false' && radios[x].checked == true) ){  
				checkrightflag = 1;
			}
		}  
		if(0 == checkrightflag){
			rid.style.color = 'black';  
			errornum--;
		}
	}  
	allerrornum = allerrornum + errornum;

	forms = document.getElementById('form3');  
	errornum = forms.length/2;
	for (i=0; i<forms.length/2; i++) {  
		radios = document.getElementsByName(forms.elements[i*2].name);  
		rid = document.getElementById('text' + radios[0].name);  
		rid.style.color = 'red';  
		checkrightflag = 1;
		for(var x=0; x<radios.length; x++){  
			if(radios[x].checked == true  && radios[x].value == 'true' ){  
				checkrightflag = 0;
			}
		} 
		if(0 == checkrightflag){
			rid.style.color = 'black';  
			errornum--;
		}
	}  
	rid = document.getElementById('errornum');
	allerrornum = allerrornum + errornum;
	rid.innerHTML = allerrornum;
	rid = document.getElementById('errorrate');
	var errrate = 100.0 - (allerrornum * 1.0) / totalnum * 100; 
	rid.innerHTML = errrate.toFixed(2); 
	document.getElementById('ierrorrate').value = errrate.toFixed(2); 
	postData = 'studentname=%E8%AE%A1%E7%AE%97%E6%9C%BA%E5%9F%BA%E7%A1%80'; 
	postData += '&errorrate='; 
	postData += errrate.toFixed(2); 
	postData += '&examunit=2'; 
	document.getElementById('commitButton').disabled=true; 
	submitForm();	
		alert(window.sessionStorage.getItem('leave-times'))
	}   
	window.onload=init;
	//一个小时，按秒计算，自己调整! 
	var maxtime = time*60 
	function CountDown(){ 
		if(maxtime>=0){ 
			minutes = Math.floor(maxtime/60); 
			seconds = Math.floor(maxtime%60); 
			msg = "距离结束还有"+minutes+"分"+seconds+"秒"; 
			document.all["timer"].innerHTML=msg; 
			if(maxtime == 5*60) alert('注意，还有5分钟!'); 
				--maxtime; 
		} 
		else{ 
			clearInterval(timer); 
			document.getElementById('status').innerHTML='做题时间结束'
			commit();
			console.log(a)
		} 
	} 

	function begin(){
		timer = setInterval("CountDown()",1000); 
	}

	let isCut = false
	let lastTime;
	// 监听器
	document.addEventListener('visibilitychange', () => {
	let state = document.visibilityState
		if (state == "hidden") {
			recordTime()
			document.title = "谁让你切屏的！！！--tab1"
		} else {
			showTimeDiff()

			document.title = "我可知道你干了什么！！！"
		}
	})

	//分屏监听
	window.onblur = () => {
		countTimes();
		recordTime()
		document.title = "你居然还切屏？！？！？--tab1"
	}
	window.onfocus = () => {
		showTimeDiff()
		document.title = "你被发现了！--tab1"
	}
	//切出时间
	function recordTime() {
		isCut = true
		lastTime = Date.now()
	}
	//时间差
	function showTimeDiff() {
		if (isCut) {
			let timeDiff = (Date.now() - lastTime) / 1000;
			console.log(timeDiff);
			isCut = false
		}
	}
	//窗口切换次数

	function countTimes() {
		let store = window.sessionStorage.getItem('leave-times')
		if (store === null) {
			window.sessionStorage.setItem('leave-times', 0)
			return
		}
		store++;
	window.sessionStorage.setItem('leave-times', store);
	}

